﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cheetah_Fast_Banking_App
{
    public class Transaction
    {
        public string Description { get; set; }
        public DateTime Date { get; set; }
        public Decimal Amount { get; set; }
        public Guid ID { get; set; }

        public TransactionType TransType { get; set; }

        public enum TransactionType
        {
            deposit,
            withdrawal,
            futuredeposit,
            futurewithdrawal,
            negativebalance
        }

        public Decimal CurrentBalance { get; set; }

        public Transaction(string description, DateTime date, Decimal amount)
        {
            Description = description;
            Date = date;
            Amount = amount;
            ID = Guid.NewGuid();
        }

        public Transaction(string description, DateTime date, Decimal amount, string id)
        {
            Description = description;
            Date = date;
            Amount = amount;
            if (id != string.Empty)
            {
                ID = Guid.Parse(id);
            }
            else
            {
                ID = Guid.NewGuid();
                //TODO:Save new Guid To XML
            }
            SetTransType();
        }

        public void SetCurrentBalance(Decimal previousBalance)
        {
            CurrentBalance = previousBalance + Amount;
        }

        public void SetTransType()
        {
            if (CurrentBalance < 0.0m)
            {
                TransType = TransactionType.negativebalance;
            }
            else if (Date > DateTime.Now)
            {
                if (Amount < 0.0m)
                {
                    TransType = TransactionType.futurewithdrawal;
                }
                else
                {
                    TransType = TransactionType.futuredeposit;
                }
            }
            else if (Amount < 0.0m)
            {
                TransType = TransactionType.withdrawal;
            }
            else
            {
                TransType = TransactionType.deposit;
            }
        }
    }
}
